<template>
  <div class="one-col-item-wrap j_akc_ubt" @click="goProductDetail">
    <div class="img-wrap-box">
      <img v-lazy="imgUrl" />
      <div v-if="product.sellOut" class="sellout">
        售罄
      </div>
      <!-- [省赚]组件 -->
      <profit
        v-if="product.profit"
        class="profit--private"
        :profitObj="product"
      ></profit>
      <!-- 打标 -->
      <img
        v-if="product.productSubscriptUrl"
        class="mark-img"
        :src="product.productSubscriptUrl"
      />
    </div>
    <div class="product-info-wrap">
      <p class="product-name">{{ product.brandStr || '' }}</p>
      <p class="product-des more_text">
        {{ product.productName || '' }}
      </p>
      <div class="product-size">
        {{ product.sizeStr || '' }}
      </div>
      <div class="price-wrap">
        <div v-if="isUserOfB">
          <div class="current-price">
            <span class="money"
              ><span class="unit_str">¥ </span>{{ product.price }}</span
            >
          </div>
          <p class="original-price">¥{{ product.tagPrice }}</p>
        </div>
        <div v-else class="price">
          <span class="unit">¥</span><span>{{ product.price }}</span
          ><span class="linePrice">¥{{ product.tagPrice }}</span>
        </div>
      </div>
      <img
        v-if="isUserOfB"
        class="cart"
        src="../../../assets/images/activity/icon_share.png"
        alt=""
        @click.stop="shareProduct"
      />
      <img
        v-else
        class="cart"
        src="../../../assets/images/activity/icon-cart.png"
        alt=""
        @click.stop="addToCart"
      />
    </div>
  </div>
</template>

<script>
import { formatImgUrl, http2https } from '@/utils/util';
import profit from '@/components/profit.vue';

export default {
  name: 'oneColumnProduct',
  components: {
    profit
  },
  props: {
    product: {
      type: Object,
      default: () => {}
    },
    index: {
      type: Number,
      default: 0
    }
  },
  data() {
    return {};
  },
  computed: {
    imgUrl() {
      if (
        this.product.productPicUrl &&
        this.product.productPicUrl.split(',')[0]
      ) {
        const productPicUrl = formatImgUrl(
          this.product.productPicUrl.split(',')[0],
          156,
          156
        );
        return http2https(productPicUrl);
      }
      return null;
    },
    isUserOfB() {
      return true;
    }
  },
  methods: {
    // 前往商品详情页
    goProductDetail() {
      this.$emit('goProductDetail');
    },
    shareProduct() {
      this.$emit('shareProduct');
    },
    addToCart() {
      this.$emit('addToCart');
    }
  }
};
</script>

<style lang="scss" scoped>
.one-col-item-wrap {
  background-color: #fff;
  border-radius: 6px;
  display: flex;
  margin-bottom: 10px;
  overflow: hidden;
  height: 156px;
  .img-wrap-box {
    position: relative;
    width: 156px;
    height: 156px;
    img {
      width: 156px;
      height: 156px;
      object-fit: cover;
      border-radius: 6px 0 0 6px;
      display: inline-block;
    }

    .profit--private {
      max-width: 156px;
    }

    .sellout {
      position: absolute;
      top: 0;
      right: 0;
      bottom: 0;
      left: 0;
      margin: auto;
      display: flex;
      justify-content: center;
      align-items: center;
      width: 65px;
      height: 65px;
      border-radius: 50%;
      color: #fff;
      font-size: 16px;
      background-color: rgba(0, 0, 0, 0.6);
    }
    .mark-img {
      position: absolute;
      top: 0;
      right: 10px;
      width: 27px;
      height: 30px;
      object-fit: cover;
      display: inline-block;
      border-radius: 0;
    }
  }

  .product-info-wrap {
    position: relative;
    padding: 10px 12px 0;
    .product-name {
      width: 171px;
      font-size: 15px;
      font-family: PingFangSC-Regular;
      color: #333;
      line-height: 21px;
      margin-bottom: 3px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
    .product-des {
      width: 171px;
      height: 34px;
      font-size: 12px;
      font-family: PingFangSC-Regular;
      color: #999;
      line-height: 17px;
      overflow: hidden;
    }
    .product-size {
      display: inline-block;
      padding: 2px 6px;
      background: #f5f5f5;
      border-radius: 2px;
      font-size: 11px;
      font-family: PingFangSC-Regular;
      color: #999;
      line-height: 16px;
      margin-top: 10px;
      max-width: 150px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }

    .price-wrap {
      position: absolute;
      left: 10px;
      bottom: 10px;

      .current-price {
        display: inline-block;
        position: relative;
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: flex-start;
        .unit_str {
          font-size: 12px;
          font-weight: bold;
          font-family: DINAlternate-Bold;
          color: rgba(230, 37, 37, 1);
          line-height: 14px;
        }
        .money {
          font-size: 22px;
          font-family: DINAlternate-Bold;
          font-weight: bold;
          color: rgba(230, 37, 37, 1);
          line-height: 30px;
        }
      }
    }

    .original-price {
      font-size: 12px;
      font-family: DINAlternate-Bold;
      font-weight: bold;
      color: #999;
      line-height: 14px;
      text-decoration: line-through;
    }
    .price {
      font-size: 22px;
      font-family: DINAlternate-Bold, DINAlternate;
      font-weight: bold;
      color: rgba(230, 37, 37, 1);
      line-height: 26px;
    }
    .unit {
      font-size: 12px;
      margin-right: 2px;
      color: rgba(230, 37, 37, 1);
      font-family: DINAlternate-Bold, DINAlternate;
      font-weight: bold;
    }

    .linePrice {
      text-decoration: line-through;
      font-size: 12px;
      font-family: DINAlternate-Bold, DINAlternate;
      font-weight: bold;
      color: rgba(153, 153, 153, 1);
      line-height: 14px;
      margin-left: 6px;
    }
    .cart {
      width: 24px;
      height: 24px;
      position: absolute;
      right: 12px;
      bottom: 12px;
    }
  }

  .more_text {
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    word-break: break-all;
    height: 40px;
    line-height: 17px;
    overflow-y: hidden;
  }
}
</style>
